package com.java1412.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author java1412
 * @since 2024-04-01 13:56:44
 */
@Service
public class HelloService {

    // 注入restTemplate
    @Resource
    private RestTemplate restTemplate;

    // 执行hystrix命令, fallbackMethod:指定兜底方案执行方法，立即返回结果，不会等待
    @HystrixCommand(fallbackMethod = "hiError")
    public String hiService(String name) {
        return restTemplate.getForObject("http://SERVICE-HI/hi?name=" + name, String.class);
    }

    public String hiError(String name) {
        return "hi," + name + ", sorry,error!";
    }
}
